<?

function dumpa($v)
{
    echo("<PRE>");
    var_dump($v);
    echo("<PRE>");
}


function niceDate($data)
{
    // Transforms BD date into hr string
    $year=substr($data, 0, 4);
    $month=substr($data, 5, 2);
    $day=substr($data, 8, 2);
    $hour=substr($data, 11, 2);
    $minute=substr($data, 14, 2);
    $second=substr($data, 17, 2);
    
    $cad=str_pad($day, 2, "0", STR_PAD_LEFT)."/".str_pad($month, 2, "0", STR_PAD_LEFT)."/".str_pad($year, 4, "0", STR_PAD_LEFT)." ".str_pad($hour, 2, "0", STR_PAD_LEFT).":".str_pad($minute, 2, "0", STR_PAD_LEFT).":".str_pad($second, 2, "0", STR_PAD_LEFT);
    
    return $cad;
}

function niceUptime($uptime)
{
    // Transforms uptime into a human-readable string
    $secs=$uptime;
    $mins=floor($secs/60);
    $secs-=$mins*60;
    
    $hours=floor($mins/60);
    $mins-=$hours*60;
    
    $days=floor($hours/24);
    $hours-=$days*24;
    
    if ($days==0)
      $cad=str_pad($hours, 2, "0", STR_PAD_LEFT).":".str_pad($mins, 2, "0", STR_PAD_LEFT).":".str_pad($secs, 2, "0", STR_PAD_LEFT);
    else if ($days==1)      
      $cad=$days." day ".str_pad($hours, 2, "0", STR_PAD_LEFT).":".str_pad($mins, 2, "0", STR_PAD_LEFT).":".str_pad($secs, 2, "0", STR_PAD_LEFT);
    else
      $cad=$days." days ".str_pad($hours, 2, "0", STR_PAD_LEFT).":".str_pad($mins, 2, "0", STR_PAD_LEFT).":".str_pad($secs, 2, "0", STR_PAD_LEFT);
      
    return $cad;
}

function optionBar()
{
?>
	
<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
	</script>
	<script type="text/javascript">
	_uacct = "UA-104249-1";
	urchinTracker();
	</script>	

<table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr> 
          <td width="14%"><div align="center"><a href="index.php" class="linkopc">Machine ranking</a></div></td>
          <td width="14%"><div align="center"><a href="system.php" class="linkopc">System ranking</a></div></td>
          <td width="12%"><div align="center"><a href="user.php" class="linkopc">User stats</a></div></td>
          <td width="12%"><div align="center"><a href="records.php" class="linkopc">Records</a></div></td>
          <td width="12%"><div align="center"><a href="genstats.php" class="linkopc">General stats</a></div></td>
<?
	if (isset($_SESSION['autenticat']))
	{
?>
          <td width="12%"><div align="center"><a href="login.php" class="linkopc">Admin</a></div></td>
<?
	}
	else
	{
?>	  
          <td width="12%"><div align="center"><a href="login.php" class="linkopc">Log In</a></div></td>
<?
	}
    
    
	if (isset($_SESSION['autenticat']))
        {
?>		
          <td width="12%"><div align="center"><a href="login.php?action=logout" class="linkopc">Log Out</a></div></td>
<?
	}
?>
       <td width="12%"><div align="center"><a href="download.php" class="linkopc">Download</a></div></td>
        </tr>
      </table>

<script type="text/javascript"><!--
google_ad_client = "pub-9147457045717302";
/* 728x90, creado 8/04/10 */
google_ad_slot = "2624852162";
google_ad_width = 728;
google_ad_height = 90;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>


<!--
<div style="margin-top: 30px;"></div>
<div style="margin: 0 auto; width: 754">
<script type="text/javascript" language="JavaScript">
	emag_course_affiliate = '2'; // sustituya por su codigo de editor id_affiliate
	emag_course_type='text';
	emag_course_output = 'html';
	emag_course_width = 754;
	emag_course_height = 87;
	emag_course_format = "cs_754x97";
	emag_max_num_courses = '3';
	emag_language = 'es';
	emag_encoding = 'iso-8859-1';     
	emag_course_section = 'contenido';
</script>
<script type="text/javascript" language="JavaScript" src="http://metrix.emagister.com/cs/show_courses.js"></script>
</div>
-->

<?
}

function theoreticalUptime($lastUptime, $lastUptimeDate)
{
    $lastUptimeDateTS=dateToTimestamp($lastUptimeDate);
    $currentDateTS=time();
    $theoreticalUptime=$lastUptime+($currentDateTS-$lastUptimeDateTS);
    
    return $theoreticalUptime;
}

function dateToTimestamp($data)
{
    // Converts DB date to unix timestamp
    $year=substr($data, 0, 4);
    $month=substr($data, 5, 2);
    $day=substr($data, 8, 2);
    $hour=substr($data, 11, 2);
    $minute=substr($data, 14, 2);
    $second=substr($data, 17, 2);
    
    $ts=mktime($hour, $minute, $second, $month, $day, $year);
    
    return $ts;
}

function dbsafe($cad)
{
    // adds slashes or returns "NULL" if string was empty
    if (strlen(trim($cad))==0)
      return "NULL";
    
    $safe=addslashes(trim($cad));
    return $safe;
}


function dbstr($cad)
{
    // makes string dbsafe and quotes it if necessary
    $safe=dbsafe($cad);
    
    if ($safe=="NULL")
      return $safe;
    
    $safe="'".$safe."'";
    return $safe;
}


function webstr($cad)
{
    $safe=htmlspecialchars($cad);
    return $safe;
}

?>
